

<?php
/*
 * Script file for Sand Dollar Media
 * ===============================================
 * Date: March 17th, 2012
 * Created By: Integration Team
 * ===============================================
 * Criteria:
 * 1. Only IM Skus 
 * 2. Only skus that have QTY > 0
 * 3. MAP field from IM file needs to go in minimal_price column if MAP is 0, leave blank 
 * 4. Suffix sku field with 'im' or 'td' - e.g. 1234td
 * 5. use custom category tree in custom_category table for categories column 
 * 6. Manufacturer name replacements - refer to cleanup_manufacturers()
 * 7. URL key should only contain alpha-numeric with only - replacing spaces - refer to URL_key()
 *  
 */
set_time_limit(3000);
require_once 'config.php';
require_once 'local/OmegaProduct.php';
$categorytemplate = new categoryClass();
$file = new FileWriter(Output_File_Name,Output_File_Directory,'a',TRUE);

$content = "";

//Product File

$product_header_array = array('v_products_id',                    //MFGPARTNO from the dnh_price table - Append -PTX
                                    'v_products_model',              //Type 2 description - should start with Manufacturer Name
                                    'v_products_image',            //Product Weight
                                    'v_products_image_med',          //Custom product category 
                                    'v_products_image_lrg',       //Type 1 - full description
                                    'v_products_name_1',         //'N' for all items
                                    'v_products_description_1',      //Manufacturer
                                    'v_products_head_keywords_tag_1',         //Type 2 description - should start with Manufacturer Name
                                    'v_manufacturers_name',            //Type 2 Description - should start with Manufacturer Name - Append with "| SDC-Photo
                                    'v_categories_name_1',            //Type 2 Description - should start with Manufacturer Name - Append with "| SDC-Photo
                                    'v_categories_name_2',      //Type 2 Description - Start with "Shop for", then Manufacturer Name and Append with "at SuperDigitalCity" 
                                    'v_categories_name_3',         //Type 2 description - should start with Manufacturer Name
                                    'v_categories_name_4',  //Type 1 - full description - Remove any colon 
                                    'EOREOR');                //UPC

$product_header_string = '"';
$product_header_string .= implode('"'.Delimiter.'"', $product_header_array);
$product_header_string .= "\"".Line_Terminator;



$file->write($product_header_string);

$result = query("Select productid as productId,mfgpartno, categoryid as categoryId
                from ".Spex_DB_name.".product where manufacturerid = 104255 and isaccessory = 0 
                and productid in (select distinct productid from productimages where productid = productId and type = 'Large') limit 100");
                

while($row = mysql_fetch_assoc($result)){

    $cda = $categorytemplate->getCategoryDisplayAttributes($row['categoryId']);
    $product = new OmegaProduct($row['productId'],$cda, True, true, true, true,false,false,false);
    
    
    if($product->get_description(2)=='')
    {
        $logfile->write(date("Y.m.d g:i a").$row['productId']." is missing Description Type 2".Line_Terminator);
        if($product->get_description(1)==''){
            $logfile->write(date("Y.m.d g:i a").$row['productId']." is missing Both Description Type 2 and 1 - Will Skip Product".Line_Terminator);
            $description = "";
        }
        else
        {
            $description = $product->get_attribute(34113319)." ".$product->get_description(1);
        }
        
    }
    else{
        $description = $product->get_description(2);
    }
    
    
    if($description<>'')
        //No point in exporting the product if the required fields are missing 
    {
        
        
        
            $long_desc = $product->get_description(3);
            $short_description = $product->get_description(2);
            $description_above_pricing = "";
            if($product->get_attribute(341452)<>'')
            {
                $marketing_info = "<br/>".$product->get_attribute(341452);
            }
            else
            {
                $marketing_info = "";
            }
            if($long_desc<>"")$description_above_pricing.="<br/><span>-".$long_desc."</span>";
            
            
            $content.= '"'.cleanup($row['productId']).'","'.
                cleanup($row['mfgpartno']).'","'.
                cleanup($product->get_resource('','100/100')).'","'.
                cleanup($product->get_resource('160')).'","'.
                cleanup($product->get_resource('300')).'","'.
                cleanup($product->get_description(1)).'","'.
                cleanup($product->techspecs).'","'.
                cleanup($product->get_attribute(3411896)." ".$product->get_description(1)).'","'.
                cleanup($product->get_keywords()).'","'.
                cleanup($product->get_attribute(3411896)).'","'.
                cleanup($categorytemplate->get_category_name($row['categoryId'])).'","'.
                cleanup($categorytemplate->get_category_tree($row['categoryId'],TRUE,'>')).'","EOREOR"'.Line_Terminator;
    }
    
unset($product); 

    
}
if ($content <> "")
{
    $file->write($content);                
    $file->close_handle();
   
}



?>

</html>